package com.vrms.app.controller;

import com.vrms.app.aop.SystemControllerLog;
import com.vrms.app.entity.Doctor;
import com.vrms.app.entity.Patients;
import com.vrms.app.service.PatientsService;
import com.vrms.app.tools.CommonResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("patients")

@CrossOrigin
public class PatientsController {
    @Resource
    private PatientsService patientsService;

    @GetMapping("/listPage")
    @SystemControllerLog(description = "分页查询老人信息")
    public CommonResult listPage(int page, int size, String username){
        Map<String,Object> map = new HashMap();
        map.put("count",patientsService.count(username));
        map.put("data",patientsService.listPage(page,size,username));
        return CommonResult.success(map);
    }

    @PostMapping("/save")
    @SystemControllerLog(description = "添加老人")
    public CommonResult save(@RequestBody Patients patients){
        return CommonResult.success(patientsService.save(patients));
    }

    @PostMapping("/update")
    @SystemControllerLog(description = "更新老人信息")
    public CommonResult update(@RequestBody Patients patients){
        return CommonResult.success(patientsService.update(patients));
    }

    @PostMapping("/remove")
    @SystemControllerLog(description = "根据ID删除老人信息")
    public CommonResult remove(int id){
        return CommonResult.success(patientsService.remove(id));
    }

    @PostMapping("/list")
    @SystemControllerLog(description = "查询所有老人信息")
    public CommonResult list(){
        return CommonResult.success(patientsService.list());
    }
}
